package com.chixigua.chaos.controller;

import com.alibaba.fastjson.JSONObject;
import com.chixigua.chaos.utils.AliyunOSSUtil;
import com.chixigua.chaos.utils.FileUtils;
import com.chixigua.chaos.utils.JsonResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/upload")
public class FileController {
    private Logger logger = LoggerFactory.getLogger(this.getClass());


    @RequestMapping(value = "/image",method = RequestMethod.POST,produces = "application/json;charset=UTF-8")
    public JSONObject uploadImage(MultipartFile file) {
        logger.info("上传图片");
        String upload = null;
        try {
            upload = AliyunOSSUtil.upload(1, FileUtils.multipartFileToFile(file));
        } catch (Exception e) {
            e.printStackTrace();
        }
        return JsonResult.successJson("https://lv-yuan.oss-cn-beijing.aliyuncs.com/" + upload);
    }
    @RequestMapping(value = "/movie",method = RequestMethod.POST,produces = "application/json;charset=UTF-8")
    public JSONObject uploadMovic(MultipartFile file) {
        logger.info("上传图片");
        String upload = null;
        try {
            upload = AliyunOSSUtil.upload(2,FileUtils.multipartFileToFile(file));
        } catch (Exception e) {
            e.printStackTrace();
        }
        return JsonResult.successJson("https://lv-yuan.oss-cn-beijing.aliyuncs.com/" + upload);
    }



}
